import { useState } from "react";

import SecurityContext from "../contexts/securutyContext";

const SecurityProvider = ({ children }) => {
  const [loggedIn, setLoggedIn] = useState(false);
  const [user, setUser] = useState(null);

  const login = (username, password) => {
    if (user === null) {
      setUser({ username, password });
      setLoggedIn(true);
    }
  };

  const logout = () => {
    setUser(null);
    setLoggedIn(false);
  };

  return (
    <SecurityContext.Provider
      value={{
        login,
        logout,
        loggedIn,
        user,
      }}
    >
      {children}
    </SecurityContext.Provider>
  );
};

export default SecurityProvider;
